package br.com.center.loja.ws.dto.converter;

import java.util.ArrayList;
import java.util.List;

import br.com.center.loja.model.Street;
import br.com.center.loja.ws.dto.StreetDTO;

public class StreetDTOConverter implements Converter<Street, StreetDTO> {

	private CityDTOConverter cityConverter = new CityDTOConverter();
	private NeighborhoodDTOConverter neighborhoodConverter = new NeighborhoodDTOConverter();
	
	@Override
	public StreetDTO to(Street element) {
		StreetDTO dto = new StreetDTO();
		dto.setCity(cityConverter.to(element.getCity()));
		dto.setCode(element.getCode());
		dto.setName(element.getName());
		dto.setNeighborhood(neighborhoodConverter.to(element.getNeighborhood()));
		dto.setState(element.getState());
		dto.setType(element.getType());
		dto.setZipCode(element.getZipCode());
		
		return dto;
	}

	@Override
	public Street from(StreetDTO element) {
		Street street = new Street();
		street.setCity(cityConverter.from(element.getCity()));
		street.setCode(element.getCode());
		street.setName(element.getName());
		street.setNeighborhood(neighborhoodConverter.from(element.getNeighborhood()));
		street.setState(element.getState());
		street.setType(element.getType());
		street.setZipCode(element.getZipCode());
		
		return street;
	}

	@Override
	public List<StreetDTO> to(List<Street> elements) {
		List<StreetDTO> result = new ArrayList<StreetDTO>();
		
		for (Street element : elements) {
			result.add(to(element));
		}
		
		return result;
	}

	@Override
	public List<Street> from(List<StreetDTO> elements) {
		List<Street> result = new ArrayList<Street>();
		
		for (StreetDTO element : elements) {
			result.add(from(element));
		}
		
		return result;
	}
}
